package cdc.retrofit.official.simpleservice;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class SimpleService {
	public static final String API_URL = "https://api.github.com";

	public static void main(String[] args) {
		Retrofit retrofit = new Retrofit.Builder().baseUrl(API_URL).addConverterFactory(GsonConverterFactory.create())
				.build();
		// Create an instance of our GitHub API interface.
		GitHub github = retrofit.create(GitHub.class);
		// Create a call instance for looking up Retrofit contributors.
		Call<List<Contributor>> call = github.contributors("square", "retrofit");
		// Fetch and print a list of the contributors to the library.
		call.enqueue(new Callback<List<Contributor>>() {
			@Override
			public void onResponse(Call<List<Contributor>> call, Response<List<Contributor>> response) {
				// TODO Auto-generated method stub
				getUrl(call);
				List<Contributor> contributors = response.body();
				for (Contributor contributor : contributors) {
					System.out.println(contributor.getContributions() + " (" + contributor.getAvatar_url() + ")");
				}
			}
			@Override
			public void onFailure(Call<List<Contributor>> call, Throwable t) {
				// TODO Auto-generated method stub

			}

		});
	}

	private static void getUrl(Call<List<Contributor>> call) {
		String path = call.request().url().url().toString();
		System.out.println("请求路径=" + path);
	}

}
